<template>
  <el-dialog title="选择面试岗位" v-model="open" width="60%" @close="handleDialogClose" append-to-body>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" label-width="68px">
        <el-form-item label="行业名称" prop="sectorName">
          <el-input
              v-model="queryParams.sectorName"
              placeholder="请输入行业名称"
              clearable
              @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-table v-loading="loading" :data="questionSectorList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column label="行业图片" align="center" prop="sectorImage" width="100">
          <template #default="scope">
            <image-preview :src="scope.row.sectorImage" :width="50" :height="50"/>
          </template>
        </el-table-column>
        <el-table-column label="行业名称" align="center" prop="sectorName"/>
        <el-table-column label="行业描述" align="center" prop="sectorDesc"/>
        <el-table-column label="状态" align="center" prop="sectorStatus">
          <template #default="scope">
            <tc-status :status="scope.row.sectorStatus"/>
          </template>
        </el-table-column>
      </el-table>

      <pagination
          v-show="total>0"
          :total="total"
          v-model:page="queryParams.pageNum"
          v-model:limit="queryParams.pageSize"
          @pagination="getList"
          style="position: relative !important;"
      />
    </div>

    <template #footer>
      <div class="dialog-footer">
        <el-button type="primary" @click="submitSelect">确 定</el-button>
        <el-button @click="handleDialogClose">取 消</el-button>
      </div>
    </template>
  </el-dialog>

</template>

<script setup name="SectorSelect">
import TcStatus from '@/components/TcStatus/index';
import {
  listQuestionSector
} from "@/api/question/questionSector";

const {proxy} = getCurrentInstance();

const emit = defineEmits(['selectChange', 'close', 'submit'])

const questionSectorList = ref([]);
const open = ref(true);
const loading = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("");
const selectSectors = ref([]);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    sectorName: null,
    sectorDesc: null,
    sectorImage: null,
    sectorStatus: null,
  },
  rules: {}
});

const {queryParams, form, rules} = toRefs(data);

/** 查询面试岗位列表 */
function getList() {
  loading.value = true;
  listQuestionSector(queryParams.value).then(response => {
    questionSectorList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  selectSectors.value = selection;
}

/** 模态框关闭事件 */
function handleDialogClose() {
  emit('close')
}

/** 确认选择 */
function submitSelect() {
  emit('submit', selectSectors.value)
}

getList();
</script>
